#ifndef CUSTOMGRAPHICSVIEW_H
#define CUSTOMGRAPHICSVIEW_H

#include <QGraphicsView>
#include <QPointF>
#include <QMouseEvent>

class CustomGraphicsView : public QGraphicsView
{
    Q_OBJECT

public:
    enum DrawMode { RectMode,
                    LineMode,
                    EllipseMode
    };

    explicit CustomGraphicsView(QWidget *parent = nullptr);

    void setDrawMode(DrawMode mode);

signals:
    void mouseClicked(const QPointF &pos);
    void mouseMoved(const QPointF &pos);
    void mouseReleased(const QPointF &pos);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    DrawMode currentDrawMode;
    bool isDrawing = false;
    QPointF startPoint;
    QGraphicsRectItem *rectItem = nullptr;
    QGraphicsLineItem *lineItem = nullptr;
    QGraphicsEllipseItem *ellipseItem = nullptr;
    QList<QGraphicsEllipseItem*> ellipseItems;

    // 辅助函数，用于创建新的椭圆项
    QGraphicsEllipseItem* createEllipseItem(const QRectF &rect, const QPen &pen, const QBrush &brush);

};

#endif // CUSTOMGRAPHICSVIEW_H
